

function GlobalReger(f){
	var w = window;
	while (w != top) {
		f(w);
		w = w.parent;
	}
}



/**
Time Opration Java Script Function Group.
**/

top.TimeOprationJavaScriptFunctions = 
	undefined!=top.TimeOprationJavaScriptFunctions
	?top.TimeOprationJavaScriptFunctions:{
	/** XXX Inner. */
	_ : {
		beginYear : 1900
		,beginWeek : 1
		,monthHeadWeek : [0,3,3,6,1,4,6,2,5,0,3,5]
		,monthHeadWeekBissextileYear : [0,3,4,0,2,5,0,3,6,1,4,6]
	}
	,_TimeStringWasher : function(s,dsp){
		if ('string'!=typeof s||'string'!=typeof dsp){
			return;
		}
		var n = '';
		for (var k = 0; k < s.length; k++){
			var t = s.charAt(k);
			if (isNaN(parseInt(t))){
				n += dsp;
			} else {
				n += t;
			}
		}
		return n;
	}
	/** XXX Fast Defineder. */
	,today : function(){
		return new Day();
	}
	,now : function(){
		return new Time();
	}
	,toDay : function(s,f){
		var _t = this;
		if ('string'!=typeof s){
			return;
		}
		var dsp = '-';
		var ts = _t._TimeStringWasher(s, dsp);
		var a = ts.split(dsp);
		var y = a.length > 0 ? parseInt(a[0].replace(/\b0/,'')) : 1;
		var m = a.length > 1 ? parseInt(a[1].replace(/\b0/,'')) : 1;
		var d = a.length > 2 ? parseInt(a[2].replace(/\b0/,'')) : 1;
		if (isNaN(y)||isNaN(m)||isNaN(d)){
			if ('function'==typeof f){
				f(s);
			}
		} else {
			return new Day(y,m,d);
		}
	}
	,toTime : function(s,f){
		var _t = this;
		if ('string'==typeof s){
			var dsp = ':';
			var dspi = s.indexOf(' ');
			var d = _t.today();
			if (dspi > 1){
				d = _t.toDay(s,f);
			}
			var ts = _t._TimeStringWasher
				(dspi > 0 ? s.substring(dspi + 1) : s, dsp);
			var a = ts.split(dsp);
			var h = a.length > 0 ? parseInt(a[0].replace(/\b0/,'')) : 0;
			var m = a.length > 1 ? parseInt(a[1].replace(/\b0/,'')) : 0;
			var s = a.length > 2 ? parseInt(a[2].replace(/\b0/,'')) : 0;
			if (isNaN(h)||isNaN(m)||isNaN(s)){
				if ('function'==typeof f){
					f(s);
				}
			} else {
				return new Time(h,m,s,d);
			}
		} else if ('number'==typeof s){
			var ms;
			ms = s % new Time().MaxMS;
			var hour = ms / 3600000;
			ms = s % 3600000;
			var minute = ms / 60000;
			ms = s % 60000;
			var second = ms / 1000;
			return new Time(hour, minute, second);
		}
	}
	/** XXX Test Order. */
	,o : function(begin,end,isTime){
		if (!begin||!end){
			return;
		}
		if (undefined==isTime){
			if (true
			&& 'object'==typeof begin
			&& begin instanceof Day
			&& 'object'==typeof end
			&& end instanceof Day){
				if (end.year > begin.year){
					return 1;
				} else if (end.year < begin.year){
					return -1;
				} else {
					if (end.month > begin.month){
						return 1;
					} else if (end.month < begin.month){
						return -1;
					} else {
						if (end.day > begin.day){
							return 1;
						} else if (end.day < begin.day){
							return -1;
						} else {
							return 0;
						}
					}
				}
			} else if (true
			&& 'object'==typeof begin
			&& begin instanceof Day
			&& 'object'==typeof end
			&& end instanceof Time){
				return this.o(begin, end.day);
			} else if (true
			&& 'object'==typeof begin
			&& begin instanceof Time
			&& 'object'==typeof end
			&& end instanceof Day){
				return this.o(begin.day, end);
			} else if (true
			&& 'object'==typeof begin
			&& begin instanceof Day
			&& 'string'==typeof end){
				return this.o(begin, this.toDay(end));
			} else if (true
			&& 'string'==typeof begin
			&& 'object'==typeof end	
			&& end instanceof Day){
				return this.o(this.toDay(begin) ,end);
			} else if (true
			&& 'object'==typeof begin
			&& begin instanceof Time
			&& 'object'==typeof end
			&& end instanceof Time){
				if (begin.day&&end.day){
					var t = this.o(begin.day, end.day);
					if (t){
						return t;
					}
				}
				if (end.hour > begin.hour){
					return 1;
				} else if (end.hour < begin.hour){
					return -1;
				} else {
					if (end.minute > begin.minute){
						return 1;
					} else if (end.minute < begin.minute){
						return -1;
					} else {
						if (end.second > begin.second){
							return 1;
						} else if (end.second < begin.second){
							return -1;
						} else {
							return 0;
						}
					}
				}
			} else if (true
			&& 'object'==typeof begin
			&& begin instanceof Time
			&& 'string'==typeof end){
				return this.o(begin, this.toTime(end));
			} else if (true
			&& 'string'==typeof begin
			&& 'object'==typeof end	
			&& end instanceof Time){
				return this.o(this.toTime(begin) ,end);
			}
		} else {
			if (isTime){
				if (true
				&& 'object'==typeof begin
				&& begin instanceof Time
				&& 'object'==typeof end
				&& end instanceof Time){
					return this.o(begin, end);
				} else if (true
				&& 'object'==typeof begin
				&& begin instanceof Time
				&& 'string'==typeof end){
					return this.o(begin, this.toTime(end) ,isTime);
				} else if (true
				&& 'string'==typeof begin
				&& 'object'==typeof end	
				&& end instanceof Time){
					return this.o(this.toTime(begin) ,end, isTime);
				}
			} else {
				if (true
				&& 'object'==typeof begin
				&& begin instanceof Day
				&& 'object'==typeof end
				&& end instanceof Day){
					return this.o(begin, end);
				} else if (true
				&& 'object'==typeof begin
				&& begin instanceof Day
				&& 'object'==typeof end
				&& end instanceof Time){
					this.o(begin, end.day);
				} else if (true
				&& 'object'==typeof begin
				&& begin instanceof Time
				&& 'object'==typeof end
				&& end instanceof Day){
					this.o(begin.day, end);
				} else if (true
				&& 'object'==typeof begin
				&& begin instanceof Time
				&& 'object'==typeof end
				&& end instanceof Time){
					this.o(begin.day, end.day);
				} else if (true
				&& 'object'==typeof begin
				&& begin instanceof Day
				&& 'string'==typeof end){
					this.o(begin, this.toDay(end));
				} else if (true
				&& 'string'==typeof begin
				&& 'object'==typeof end	
				&& end instanceof Day){
					this.o(this.toDay(begin) ,end);
				} else if (true
				&& 'object'==typeof begin
				&& begin instanceof Time
				&& 'string'==typeof end){
					this.o(begin.day, this.toDay(end));
				} else if (true
				&& 'string'==typeof begin
				&& 'object'==typeof end	
				&& end instanceof Time){
					this.o(this.toDay(begin) ,end.day);
				}
			}
		}
		
	}
	/** XXX Bissextile Year. */
	,bsY : function(p,f){
		if ('number'==typeof p){
			return p % 100 == 0 && p % 400 == 0
					|| p % 100 != 0 && p % 4 == 0;
		} else if ('object'==typeof p
			&&p instanceof Day){
			return this.bsY(p.year);
		} else if ('object'==typeof p
			&&p instanceof Time){
			return this.bsY(p.day.year);
		} else if ('string'==typeof p){
			return this.bsY(this.toDay(p,f));
		}
		return 'function'==typeof f ? f(p) : false;
	}
	/** XXX Size. */
	,sY : function(p,f){
		if ('number'==typeof p){
			return this.bsY(p,f)?366:365;
		} else if ('object'==typeof p
			&&p instanceof Day){
			return this.sY(p.year,f);
		} else if ('object'==typeof p
			&&p instanceof Time){
			return this.sY(p.day.year,f);
		} else if ('string'==typeof p){
			return this.sY(this.toDay(p,f));
		}
		if ('function'==typeof f){
			f(p);
		}
	}
	,sM : function(p,f,f2){
		if (true
		&& 'number'==typeof p
		&& 'number'==typeof f){
			switch (f) {
			case 2:
				return this.bsY(p) ? 29 : 28;
			case 4:
			case 6:
			case 9:
			case 11:
				return 30;
			default:
				return 31;
			}
			if ('function'==typeof f2){
				f2(p,f);
			}
		} else {
			if ('object'==typeof p
				&&p instanceof Day){
				return this.sM(p.year,p.month,f);
			} else if ('object'==typeof p
				&&p instanceof Time){
				return this.sM(p.day.year,p.day.month,f);
			} else if ('string'==typeof p){
				return this.sM(this.toDay(p,f));
			}
			if ('function'==typeof f){
				f(p);
			}
		} 
	}
	/** XXX Week Index. */
	,wY : function(p,f){
		if ('number'==typeof p){
			var w = this._.beginWeek;
			if (p > this._.beginYear){
				for (var k = this._.beginYear; k < p; k++){
					w ++;
					if (this.bsY(k)){
						w ++;
					}
				}
				return w % 7;
			} else if (p < this._.beginYear) {
				for (var k = this._.beginYear; k > p; k--){
					w --;
					if (this.bsY(k)){
						w --;
					}
					if (w < 0){
						w += 7;
					}
				}
				return w;
			}
			return 1;
		} else if ('object'==typeof p
			&&p instanceof Day){
			return this.wY(p.year,f);
		} else if ('object'==typeof p
			&&p instanceof Time){
			return this.wY(p.day.year,f);
		} else if ('string'==typeof p){
			return this.wY(this.toDay(p,f));
		}
		if ('function'==typeof f){
			f(p);
		}
	}
	,wM : function(p,f,f2){
		if (true
		&& 'number'==typeof p
		&& 'number'==typeof f){
			var w = this.bsY(p) 
				? this._.monthHeadWeekBissextileYear[f - 1]
				: this._.monthHeadWeek[f - 1];
			return (w + this.wY(p,f2)) % 7;
		} else {
			if ('object'==typeof p
				&&p instanceof Day){
				return this.wM(p.year,p.month,f);
			} else if ('object'==typeof p
				&&p instanceof Time){
				return this.wM(p.day.year,p.day.month,f);
			} else if ('string'==typeof p){
				return this.wM(this.toDay(p,f));
			}
			if ('function'==typeof f){
				f(p);
			}
		} 
	}
	,wD : function(y,m,d,f){
		if (true
		&& 'number'==typeof y
		&& 'number'==typeof m
		&& 'number'==typeof d){
			var w = (d + this.wM(y,m,f)) % 7 - 1;
			return w < 0 ? w + 7 : w;
		} else {
			if ('object'==typeof y
				&&y instanceof Day){
				return this.wD(y.year,y.month,y.day,m);
			} else if ('object'==typeof y
				&&y instanceof Time){
				return this.wD(y.day.year,y.day.month,y.day.day,m);
			} else if ('string'==typeof y){
				return this.wD(this.toDay(y,m));
			}
			if ('function'==typeof m){
				m(p);
			}
		} 
	}
	/** XXX Time Runner. */
	,backD : function(day,n){
		if (!n){
			n = 1;
		}
		if (true
		&&'object'==typeof day
		&&day instanceof Day){
			var y = day.year;
			var m = day.month;
			var d = day.day;
			for (var k = 1; k <= n; k++){
				if (d > 1){
					d --;
				} else if (m > 1) {
					m --;
					d = this.sM(y, m);
				} else {
					y --;
					m = 12;
					d = this.sM(y, m);
				}
			}
			return new Day(y,m,d);
		} else if (true
		&&'object'==typeof day
		&&day instanceof Time){
			return this.backD(day.day,n);
		} else if ('string'==typeof day){
			return this.backD(this.toDay(p),n);
		}
	}
	,backM : function(day,n){
		if (!n){
			n = 1;
		}
		if (true
		&&'object'==typeof day
		&&day instanceof Day){
			var y = day.year;
			var m = day.month;
			var d = day.day;
			for (var k = 1; k <= n; k++){
				if (m > 1){
					m --;
				} else {
					y --;
					m = 12;
				}
			}
			return new Day(y,m,d);
		} else if (true
		&&'object'==typeof day
		&&day instanceof Time){
			return this.backM(day.day,n);
		} else if ('string'==typeof day){
			return this.backM(this.toDay(p),n);
		}
	}
	,forwordD : function(day,n){
		if (!n){
			n = 1;
		}
		if (true
		&&'object'==typeof day
		&&day instanceof Day){
			var y = day.year;
			var m = day.month;
			var d = day.day;
			for (var k = 1; k <= n; k++){
				if (d < this.sM(y,m)){
					d ++;
				} else if (m < 12) {
					m ++;
					d = 1;
				} else {
					y ++;
					m = 1;
					d = 1;
				}
			}
			return new Day(y,m,d);
		} else if (true
		&&'object'==typeof day
		&&day instanceof Time){
			return this.forwordD(day.day,n);
		} else if ('string'==typeof day){
			return this.forwordD(this.toDay(p),n);
		}
	}
	,forwordM : function(day,n){
		if (!n){
			n = 1;
		}
		if (true
		&&'object'==typeof day
		&&day instanceof Day){
			var y = day.year;
			var m = day.month;
			var d = day.day;
			for (var k = 1; k <= n; k++){
				if (m < 12) {
					m ++;
				} else {
					y ++;
					m = 1;
				}
			}
			return new Day(y,m,d);
		} else if (true
		&&'object'==typeof day
		&&day instanceof Time){
			return this.forwordM(day.day,n);
		} else if ('string'==typeof day){
			return this.forwordM(this.toDay(p),n);
		}
	}
	/** XXX Begin Day. */
	,bY : function(p,f){
		if ('number'==typeof p){
			return new Day(p,1,1);
		} else if ('object'==typeof p
			&&p instanceof Day){
			return this.bY(p.year,f);
		} else if ('object'==typeof p
			&&p instanceof Time
			&&p.day){
			return this.bY(p.day.year,f);
		} else if ('string'==typeof p){
			return this.bY(this.toDay(p,f),f);
		}
		if ('function'==typeof f){
			f(p);
		}
	}
	,bM : function(p,f,f2){
		if (true
		&& 'number'==typeof p
		&& 'number'==typeof f){
			return new Day(p,f,1);
		} else {
			if ('object'==typeof p
				&&p instanceof Day){
				return this.bM(p.year,p.month,f);
			} else if ('object'==typeof p
				&&p instanceof Time
				&&p.day){
				return this.bM(p.day.year,p.day.month,f);
			} else if ('string'==typeof p){
				return this.bM(this.toDay(p,f),f);
			}
			if ('function'==typeof f){
				f(p);
			}
		} 
	}
	,bW : function(day,f){
		if (true
		&&'object'==typeof day
		&&day instanceof Day){
			return this.backD(day, this.wD(day));
		} else if (true
		&&'object'==typeof day
		&&day instanceof Time
		&&p.day){
			return this.bW(day.day,f);
		} else if ('string'==typeof day){
			return this.bW(this.toDay(day,f),f);
		}
		if ('function'==typeof f){
			f(day);
		}
	}
	/** XXX End Day. */
	,eY : function(p,f){
		if ('number'==typeof p){
			return new Day(p,12,this.sM(p, 12, f));
		} else if ('object'==typeof p
			&&p instanceof Day){
			return this.eY(p.year,f);
		} else if ('object'==typeof p
			&&p instanceof Time
			&&p.day){
			return this.eY(p.day.year,f);
		} else if ('string'==typeof p){
			return this.eY(this.toDay(p,f),f);
		}
		if ('function'==typeof f){
			f(p);
		}
	}
	,eM : function(p,f,f2){
		if (true
		&& 'number'==typeof p
		&& 'number'==typeof f){
			return new Day(p,f,this.sM(p, f, f2));
		} else {
			if ('object'==typeof p
				&&p instanceof Day){
				return this.eM(p.year,p.month,f);
			} else if ('object'==typeof p
				&&p instanceof Time
				&&p.day){
				return this.eM(p.day.year,p.day.month,f);
			} else if ('string'==typeof p){
				return this.eM(this.toDay(p,f),f);
			}
			if ('function'==typeof f){
				f(p);
			}
		} 
	}
	,eW : function(day,f){
		if (true
		&&'object'==typeof day
		&&day instanceof Day){
			return this.forwordD(day, 6-this.wD(day,f));
		} else if (true
		&&'object'==typeof day
		&&day instanceof Time
		&&day.day){
			return this.eW(day.day,f);
		} else if ('string'==typeof day){
			return this.eW(this.toDay(day,f),f);
		}
		if ('function'==typeof f){
			f(day);
		}
	}
	/** XXX Diff. */
	,diffM : function(d1,d2){
		var diff = 0;
		var f , t , o = this.o(d1, d2);
		if (o > 0){
			f = d1;
			t = d2;
		} else if (o < 0){
			f = d2;
			t = d1;
		} else {
			return 0;
		}
		while (false
		||f.year!=t.year
		||f.month!=t.month){
			diff++;
			f = this.forwordM(f);
		}
		return diff;
	}
	,diffD : function(d1,d2){
		var diff = 0;
		var f , t , o = this.o(d1, d2);
		if (o > 0){
			f = d1;
			t = d2;
		} else if (o < 0){
			f = d2;
			t = d1;
		} else {
			return 0;
		}
		while (false
		||f.year!=t.year
		||f.month!=t.month
		||f.day!=t.day){
			diff++;
			f = this.forwordD(f);
		}
		return diff;
	}
	/** XXX Area.*/
	,areaH : function(t1,t2){
		return this.areaM(t1, t2) / 60;
	}
	,areaM : function(t1,t2){
		return this.areaS(t1, t2) / 60;
	}
	,areaS : function(t1,t2){
		if (true
		&&'object'==typeof t1
		&&t1 instanceof Time
		&&'object'==typeof t2
		&&t2 instanceof Time){
			return (((t2.hour - t1.hour) * 60)
				+ (t2.minute - t1.minute)) * 60
				+ t2.second - t1.second;
		} else if (true
		&&'string'==typeof t1
		&&'string'==typeof t2){
			return this.areaS(this.toTime(t1), this.toTime(t2));
		} else if (true
		&&'object'==typeof t1
		&&t1 instanceof Time
		&&'string'==typeof t2) {
			return this.areaS(t1, this.toTime(t2));
		} else if (true
		&&'string'==typeof t1
		&&'object'==typeof t2
		&&t2 instanceof Time) {
			return this.areaS(this.toTime(t1), t2);
		}
	}
};
GlobalReger(function(w){
	w.TimeOprationJavaScriptFunctions = top.TimeOprationJavaScriptFunctions;
});
top._T = TimeOprationJavaScriptFunctions==top._T
	?top._T:TimeOprationJavaScriptFunctions;
GlobalReger(function(w){
	w._T = top._T;
});
/** XXX Objects. */
function Day(year,month,day){
	if (true
	&&'number'==typeof year
	&&'number'==typeof month
	&&'number'==typeof day){
		this.year = parseInt(year);
		this.month = month < 1 ? 1 : month > 12 ? 12 : parseInt(month);
		this.day = day < 1 ? 1 
				: day > _T.sM(year, month) ? _T.sM(year, month) 
				: parseInt(day);
	} else {
		var d = new Date();
		this.year = d.getFullYear();
		this.month = d.getMonth() + 1;
		this.day = d.getDate();
	}
}
Day.prototype.toString = function(){
	var s = this.year + '-';
	if (this.month > 9){
		s += this.month;
	} else {
		s += '0' + this.month;
	}
	s += '-';
	if (this.day > 9){
		s += this.day;
	} else {
		s += '0' + this.day;
	}
	return s;
};
function Time(hour,minute,second,day){
	this.day = 'object'==typeof day&&day instanceof Day?day:_T.today();
	if (true
	&&'number'==typeof hour
	&&'number'==typeof minute
	&&'number'==typeof second){
		this.hour = hour > 23 ? 23 : hour < 0 ? 0 : parseInt(hour);
		this.minute = minute > 59 ? 59 : minute < 0 ? 0 : parseInt(minute);
		this.second = second > 59 ? 59 : second < 0 ? 0 : parseInt(second);
	} else {
		var d = new Date();
		this.hour = d.getHours();
		this.minute = d.getMinutes();
		this.second = d.getSeconds();
	}
};
Time.prototype.MaxMS = 86400000; 
Time.prototype.toString = function(){
	var s = '';
	if (this.hour > 9){
		s += this.hour;
	} else {
		s += '0' + this.hour;
	}
	s += ':';
	if (this.minute > 9){
		s += this.minute;
	} else {
		s += '0' + this.minute;
	}
	s += ':';
	if (this.second > 9){
		s += this.second;
	} else {
		s += '0' + this.second;
	}
	return s;
};
Time.prototype.ms = function(){
	return (this.hour * 3600 + this.minute * 60 + this.second) * 1000;
};
























